package view;



import java.io.*;
import java.math.*;
import java.util.*;

public class EncryptMessage {

    public BigInteger two;
    private static BigInteger p;  
    private static BigInteger q;
    public static BigInteger n;
    public String plaintext;
    private static BigInteger c;
    //private StringBuffer decryptText;
    public String ciphertext = new String();

	
    //private static final int BITS = 256;
    


	public EncryptMessage(BigInteger num, String plt){
		two = BigInteger.valueOf(2);
		n = num;
		//System.out.println("created with n : "+ n.toString());
		plaintext = plt;
		
		}
	 

    /* access the encrypted text */
    public String getCipherText() {
		return ciphertext;
    }
	 
	 
    public void encipher() {
		StringTokenizer t = new StringTokenizer(plaintext, "\n");
		 		
		while ( t.hasMoreTokens()) {
		    //System.out.println("******************************");
	    	String s = new String();
	    	s = t.nextToken();
			// add extra bits to the end of plaintext
		    byte[] temp = s.getBytes();
	    	byte[] rabinbytes = new byte[temp.length + 1];
					   
		    System.arraycopy(temp, 0, rabinbytes, 0, temp.length);	
						
	   		 System.arraycopy(rabinbytes, (rabinbytes.length - 2), rabinbytes, (rabinbytes.length - 1), 1);
		  
	   		 BigInteger m = new BigInteger(rabinbytes);
	   		 //System.out.println("n used: "+ n.toString());
		     c = m.modPow(two, n); 		  		     
			 ciphertext += c.toString() ;
			 ciphertext += "\n";
  
		    	   
		}
		System.out.println("full cipher text : " + ciphertext);
    }
    




}
	
















